#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "library.h"

int book_num = 0;
int surplus_book_num = 0;
int type_num = 0;
int user_num = 0;
char wgc_passwd[8] = "888888";
char wgc_name[20] = "manager";
char wgc[20] = "manager";
static int initial_number = 0;

void xiugai(void* data,void* name)
{
    char* name1 = name;
    struct book_ation* data1 = data;
    strcpy (data1 -> book_type, name1);
}

int user_cmp(void* key1, void* key2, void* data)
{
    char* name = key1;
    char* id = key2;
    struct user* data1 = data;
    return (strcmp(name, data1 -> user_name) + strcmp(id, data1 -> user_passwd));
}

int user_name_cmp(void* key, void* data)
{
    char* name = key;
    struct user* data1 = data;
    return (strcmp(name, data1 -> user_name));
}

int type_cmp(void* key, void* data)
{
    int* id = key;
    struct type_ation* data1 = data;
    return ((*id) - (data1 -> type_id));
}

int type_name_cmp(void* key, void* data)
{
    char* name = key;
    struct type_ation* data1 = data;
    return (strcmp(name, data1 -> type_name));
}

int book_cmp(void* key, void* data)
{
    int* id = key;
    struct book_ation* data1 = data;
    return ((*id) - (data1 -> book_id));
}

int book_name_cmp(void* key, void* data)
{
    char* name = key;
    struct book_ation* data1 = data;
    return (strcmp(name, data1 -> book_name));
}

void user_show(void* data)
{
    struct user* data1 = data;
    printf("用户id：%s\n",data1 -> user_id);
    printf("用户姓名：%s\n",data1 -> user_name);
    printf("用户性别：%s\n",data1 -> user_sex);
    printf("用户手机：%ld\n",data1 -> user_ipone);
    printf("用户住址：%s\n",data1 -> user_address);
    printf("用户密码：%s\n",data1 -> user_passwd);
    printf("用户当前借书总数：%d\n", data1 -> user_book_num);
    printf("用户当前借阅记录总数：%d\n", data1 -> user_record_num);
}

void type_show(void* data)
{
    struct type_ation* data1 = data;
    printf("类型id：%d\n", data1 -> type_id);
    printf("类型名称：%s\n", data1 -> type_name);
    printf("类型书籍总量：%d\n", data1 -> type_book);
    //printf("---------------------------------------\n");
}

void type_show3(void* data)
{
    struct type_ation* data1 = data;
    printf("类型名称：%s\n", data1 -> type_name);
    //printf("---------------------------------------\n");
}

void* type_show2(void* data)
{
    struct type_ation* data1 = data;
    printf("类型id：%d\n", data1 -> type_id);
    printf("类型名称：%s\n", data1 -> type_name);
    printf("类型书籍总量：%d\n", data1 -> type_book);
    return data1 -> head;
    //printf("---------------------------------------\n");
}

void* type_change(void* data)
{
    struct type_ation* data1 = data;
    return data1 -> head;
    //printf("---------------------------------------\n");
}

void* user_change(void* data)
{
    struct user* data1 = data;
    return data1 -> head;
    //printf("---------------------------------------\n");
}

void* user_change1(void* data)
{
    struct user* data1 = data;
    return data1 -> head2;
    //printf("---------------------------------------\n");
}

struct book_ation* cp(void* data)
{
    struct book_ation* yi;
    struct book_ation* data1 = data;
    yi -> book_id = data1 -> book_id;
    strcpy(yi -> book_type, data1 -> book_type);
    strcpy(yi -> book_name, data1 -> book_name);
    strcpy(yi -> book_author, data1 -> book_author);
    return yi;
}

void book_show(void* data)
{
    struct book_ation* data1 = data;
    printf("图书id：%d\n", data1 -> book_id);
    printf("图书名称：%s\n", data1 -> book_name);
    printf("图书类型：%s\n", data1 -> book_type);
    printf("图书作者：%s\n", data1 -> book_author);
    //printf("---------------------------------------\n");
}

void book_show2(void* data)
{
    struct book_ation* data1 = data;
    printf("图书名称：%s\n", data1 -> book_name);
    //printf("---------------------------------------\n");
}

void record_show(void* data)
{
    struct user_record* data1 = data;
    printf("借阅记录： %s\n", data1 -> record);
}

/////////////////////////////////////////////////



void save_user(List* head)
{
    List* su;
    List* su1;
	FILE* ua = fopen("user_ation", "w");
    FILE* ur = fopen("user_record", "w");
	FILE* ub = fopen("user_book_ation", "w");
	struct Node_wgc* ucr;
    struct Node_wgc* ucr1;
    struct Node_wgc* ucr2;
	struct user* u = (struct user*)malloc(sizeof(struct user));
    struct book_ation* u_b = (struct book_ation*)malloc(sizeof(struct book_ation));
    struct user_record* u_r = (struct user_record*)malloc(sizeof(struct user_record));
    for(ucr= head -> tou.next; ucr != &(head -> tou); ucr = ucr -> next)
    {
        su = user_change(ucr -> data);
        su1 = user_change1(ucr -> data);
        memcpy(u, ucr -> data, sizeof(struct user));
		fprintf(ua, "%s\t%s\t%s\t%ld\t%s\t%s\t%d\t%d\t", u -> user_id, u -> user_passwd, u -> user_name, u -> user_ipone, u -> user_sex, u -> user_address, u -> user_book_num, u -> user_record_num);
        for(ucr1= su -> tou.next; ucr1 != &(su -> tou); ucr1 = ucr1 -> next)
        {
            memcpy(u_b, ucr1 -> data, sizeof(struct book_ation));
            fprintf(ub, "%d\t%s\t%s\t%s\t", u_b -> book_id, u_b -> book_type, u_b -> book_name, u_b -> book_author);
        }
        for(ucr2= su1 -> tou.next; ucr2 != &(su1 -> tou); ucr2 = ucr2 -> next)
        {
            memcpy(u_r, ucr2 -> data, sizeof(struct user_record));
            fprintf(ur, "%s\t", u_r -> record);
        }
        /*for(int n = 0; n < u_a.user_record_num; n++)
        {
            fscanf(ur, "%s\t", u_r.record);
            establish_node(u_a.head2, &u_r, _MODE_AFTER);
        }*/
    }
	fclose(ua);
    fclose(ur);
    fclose(ub);
}


void save_type(List* head)
{
    List* st;
    FILE* wgc_ty = fopen("type_ation", "w");
	FILE* wgc_bo = fopen("book_ation", "w");
	struct Node_wgc* ucr;
    struct Node_wgc* ucr1;
    struct book_ation* t_b = (struct book_ation*)malloc(sizeof(struct book_ation));
	struct type_ation* t_a = (struct type_ation*)malloc(sizeof(struct type_ation));
    for(ucr= head -> tou.next; ucr != &(head -> tou); ucr = ucr -> next)
    {
        memcpy(t_a, ucr -> data, sizeof(struct type_ation));
		fprintf(wgc_ty, "%d\t%s\t%d\t", t_a -> type_id, t_a -> type_name, t_a -> type_book);
        st = type_change(ucr -> data);
        for(ucr1= st -> tou.next; ucr1 != &(st -> tou); ucr1 = ucr1 -> next)
        {
            memcpy(t_b, ucr1 -> data, sizeof(struct book_ation));
            fprintf(wgc_bo, "%d\t%s\t%s\t%s\t", t_b -> book_id, t_b -> book_type, t_b -> book_name, t_b -> book_author);
        }
    }

	fclose(wgc_ty);
    fclose(wgc_bo);
}

void* read_user()
{
    struct user* wg = NULL;
	FILE* ua = fopen("user_ation", "r");
    FILE* ur = fopen("user_record", "r");
	FILE* ub = fopen("user_book_ation", "r");
	
    struct user u_a;
    struct user_record u_r;
    struct book_ation u_b;

    List* user_head = establish_head(sizeof(struct user));
    if(user_head == NULL)
    {
        perror("1");
        return NULL;
    }
    
    for(int i = 0; i < user_num; i++)
    {
        fscanf(ua, "%s\t%s\t%s\t%ld\t%s\t%s\t%d\t%d\t", u_a.user_id, u_a.user_passwd, u_a.user_name, &(u_a.user_ipone), u_a.user_sex, u_a.user_address, &(u_a.user_book_num), &(u_a.user_record_num));
        u_a.head = establish_head(sizeof(struct book_ation));
        if(u_a.head == NULL)
        {
            perror("2");
            return NULL;
        }
        u_a.head2 = establish_head(sizeof(struct user_record));
        if(u_a.head == NULL)
        {
            perror("2");
            return NULL;
        }
        //wg = find_wgc(user_head, u_a.user_name, user_name_cmp);
        
        for(int j = 0; j < (u_a.user_book_num); j++)
        {
            fscanf(ub, "%d\t%s\t%s\t%s\t", &(u_b.book_id), u_b.book_type, u_b.book_name, u_b.book_author);
            establish_node(u_a.head, &u_b, _MODE_AFTER);
        }
        for(int n = 0; n < u_a.user_record_num; n++)
        {
            fscanf(ur, "%s\t", u_r.record);
            establish_node(u_a.head2, &u_r, _MODE_AFTER);
        }
        establish_node(user_head, &u_a, _MODE_AFTER);
        //ergodic(user_head, user_show);
    }
	fclose(ua);
    fclose(ur);
    fclose(ub);
    return user_head;
}

/*void read_user()
{
    List* su;
    List* su1;
	FILE* ua = fopen("user_ation", "w");
    FILE* ur = fopen("user_record", "w");
	FILE* ub = fopen("user_book_ation", "w");
	struct Node_wgc* ucr;
    struct Node_wgc* ucr1;
    struct Node_wgc* ucr2;
	struct user* u = (struct user*)malloc(sizeof(struct user));
    struct book_ation* u_b = (struct book_ation*)malloc(sizeof(struct book_ation));
    struct user_record* u_r = (struct user_record*)malloc(sizeof(struct user_record));
    for(ucr= head -> tou.next; ucr != &(head -> tou); ucr = ucr -> next)
    {
        su = user_change(ucr -> data);
        su1 = user_change1(ucr -> data);
        memcpy(u, ucr -> data, sizeof(struct user));
		fprintf(ua, "%s\t%s\t%s\t%ld\t%s\t%s\t%d\t%p\t%p\t", u -> user_id, u -> user_passwd, u -> user_name, u -> user_ipone, u -> user_sex, u -> user_address, u -> user_book_num, u -> head, u -> head2);
        for(ucr1= su -> tou.next; ucr1 != &(su -> tou); ucr1 = ucr1 -> next)
        {
            memcpy(u_b, ucr1 -> data, sizeof(struct book_ation));
            fprintf(ub, "%d\t%s\t%s\t%s\t", u_b -> book_id, u_b -> book_type, u_b -> book_name, u_b -> book_author);
        }
        for(ucr2= su1 -> tou.next; ucr2 != &(su1 -> tou); ucr2 = ucr2 -> next)
        {
            memcpy(u_r, ucr2 -> data, sizeof(struct user_record));
            fprintf(ur, "%s\t", u_r -> record);
        }
    }
	fclose(ua);
    fclose(ur);
    fclose(ub);
}*/

void* read_type()
{
    List* st = NULL;
    struct type_ation* wg = NULL;
    FILE* wgc_ty = fopen("type_ation", "r");
	FILE* wgc_bo = fopen("book_ation", "r");
    
    struct type_ation t_w;
    struct book_ation b_w;
    List* type_head = establish_head(sizeof(struct type_ation));
    if(type_head == NULL)
    {
        perror("1");
        return NULL;
    }
    for(int i = 0; i < type_num; i++)
    {
        fscanf(wgc_ty, "%d\t%s\t%d\t", &t_w.type_id, t_w.type_name, &t_w.type_book);
        t_w.head = establish_head(sizeof(struct book_ation));
        if(t_w.head == NULL)
        {
            perror("2");
            return NULL;
        }
        establish_node(type_head, &t_w, _MODE_AFTER);
        wg = find_wgc(type_head, t_w.type_name, type_name_cmp);
        for(int j = 0; j < t_w.type_book; j++)
        {
            fscanf(wgc_bo, "%d\t%s\t%s\t%s\t", &b_w.book_id, b_w.book_type, b_w.book_name, b_w.book_author);
            establish_node(wg -> head, &b_w, _MODE_AFTER);
        }
    }

	fclose(wgc_ty);
    fclose(wgc_bo);
    return type_head;
}


void save_num()
{
    FILE* num = fopen("other_news", "w");
    fprintf(num, "%d\t%d\t%d\t%d\t%s\t%s\t%d\t",book_num, surplus_book_num, type_num, user_num, wgc_passwd, wgc_name, initial_number);
    fclose(num);
}

void read_num()
{
    FILE* num = fopen("other_news", "r");
    if(num == NULL)
    {
        //perror("fopen fail");
        return ;
    }
    fscanf(num, "%d\t%d\t%d\t%d\t%s\t%s\t%d\t",&book_num, &surplus_book_num, &type_num, &user_num, wgc_passwd, wgc_name, &initial_number);
    fclose(num);
}

void save(void* data1, void*data2)
{
    save_user(data1);
    save_type(data2);
    save_num();
}

/*void read(void* data1, void*data2)
{
    read_num();
    //read_user(data1);
    read_type(data2);
}*/
///////////////////////////////////////////////

int main()
{
    system("clear");
    struct tm *t;
    time_t tt;
    int num, i, j, k, f, n;
    char N[40];
    int id, idd;
    char a;
    char name[40];
    char name2[40];
    char recort_time[150];
    struct book_ation* bo;
    struct book_ation book;
    struct type_ation type;
    struct type_ation* ty;
    struct user* us;
    struct user use;
    read_num();
    List* user_head = establish_head(sizeof(struct user)); //创建用户链表头
    if(NULL == user_head)
    {
        printf("创建头失败\n");
        return 1;
    }
    List* p = NULL;
    List* type_head = NULL;
    if(user_num > 0)
    {
        user_head = read_user();
    }
    else
    {
        user_head = establish_head(sizeof(struct user)); //创建图书类型链表头
    }
    if(type_num > 0)
    {
         type_head = read_type();
    }
    else
    {
        type_head = establish_head(sizeof(struct type_ation)); //创建图书类型链表头
    }
	//List* head_wgc = read_wgc();
    printf("-------------------欢迎使用图书馆管理系统----------------------\n");
    while(1)
    {
        printf("---------------您可以进行以下操作---------------\n");
        printf("1、用户登陆\n");
        printf("2、管理员登陆\n");
        printf("3、查看图书信息\n");
        printf("4、退出\n");
        printf("请输入你的选项：");
        scanf("%s",N);
        if(strcmp(N, "1") == 0) 
        {
            if(user_num < 1)
            {
                printf("目前暂无用户，请先联系管理员注册用户\n");
                printf("返回上一级------>请按1回车\n\n退出系统------->按任意建回车\n请输入你的选项：");
                scanf("%s", name);
                if(strcmp(name, "1") == 0)
                {
                    system("clear");
                    continue;
                }
                else
                {
                    system("clear");
                    break;
                }
            }
            a = 'c';
            printf("请输入你的用户名：");
            scanf("%s", name);
            while(1)
            {
                if(strlen(name) > 20)
                {
                    printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                    printf("请重新输入新的用户密码：");
                    scanf("%s", name);
                }
                else
                {
                    break;
                }
            }
            printf("请输入你的用户密码：");
            scanf("%s", name2);
            while(1)
            {
                if(strlen(name2) > 8)
                {
                    printf("输入用户密码格式错误 (用户密码最长为8个字符)\n");
                    printf("请重新输入新的用户密码：");
                    scanf("%s", name2);
                }
                else
                {
                    break;
                }
            }
            while(a != '\n')
            {
                a = getchar();
            }
            //ergodic(user_head, user_show);
            us = find_wgc2(user_head, name, name2, user_cmp); //用户的用户名和密码比对校验
            if(us == NULL)
            {
                printf("用户或用户名错误,如果忘记，请联系管理员修改或重新注册\n返回上一级------>请按1回车\n\n退出系统按任意建回车\n请输入你的选项：");
                scanf("%s", name);
                if(strcmp(name, "1") == 0)
                {
                    system("clear");
                    continue;
                }
                else
                {
                    system("clear");
                    while(a != '\n')
                    {
                        a = getchar();
                    }
                    break;
                }
            }
            else
            {
                system("clear");
                printf("-----------------欢迎进入用户界面-----------------\n");
                while(1)
                {
                    printf("---------------您可以进行以下操作---------------\n");
                    printf("1、借阅书籍\n");
                    printf("2、归还书籍\n");
                    printf("3、查看个人借阅归还记录\n");
                    printf("4、查看个人信息\n");
                    printf("5、修改个人信息\n");
                    printf("6、退出登陆\n");
                    printf("请输入你的选项：");
                    scanf("%d", &n);
                    system("clear");
                    if(1 == n)
                    {
                        a = 'c';
                        ergodic(type_head, type_show); //便利所有图书类型
                        printf("***                     ***\n");
                        printf("请选择书籍类型名称：");
                        scanf("%s", name);
                        ty = find_wgc(type_head, name, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入名称有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {

                            if((ty -> type_book) < 1)
                            {
                                printf("该类书籍暂无库存\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                            ergodic(ty -> head, book_show); //便利该类型所有图书
                            printf("***                     ***\n");
                            printf("请选择书籍名称：");
                            scanf("%s", name2);
                            bo = find_wgc(ty -> head, name2, book_name_cmp); //书籍类型校验
                            if(NULL == bo)
                            {
                                printf("输入名称有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;  
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                            else
                            {
                                printf("确认借阅------>请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    establish_node(us -> head, bo, _MODE_AFTER); //该用户借阅书籍加1
                                    time(&tt);
                                    t = localtime(&tt);
                                    sprintf(recort_time,"%4d年%02d月%02d日->%02d:%02d:%02d->%s---->借阅书籍：%s\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, us -> user_name, bo -> book_name);
                                    establish_node(us -> head2, recort_time, _MODE_AFTER); //该用户借阅书籍记录加1
                                    (us -> user_book_num)++; //该用户借书总数加1
                                    (us -> user_record_num)++;
                                    dale_wgc(ty -> head, name2, book_name_cmp); //图书馆该类型图书信息删除
                                    surplus_book_num--; //图书馆书籍总数减1
                                    ty -> type_book--; //该类型书籍总数减1  
                                    system("clear");
                                    while(a != '\n')
                                    {
                                        a = getchar();
                                    }
                                    save_user(user_head);
                                    continue;
                                }
                                else
                                {
                                    system("clear");
                                    while(a != '\n')
                                    {
                                        a = getchar();
                                    }
                                    break;
                                }
                            }
                        } 
                    }
                    else if(2 == n)
                    {
                        a = 'c';
                        if((us -> user_book_num) < 1)
                        {
                            printf("暂无借借出信息\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        ergodic(us -> head, book_show); //便利该用户借阅中的所有图书信息
                        printf("请输入书籍名称：");
                        scanf("%s", name2);
                        bo = find_wgc(us -> head, name2, book_name_cmp); //书籍校验
                        if(NULL == bo)
                        {
                            printf("输入名称有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            //cp(bo);
                            //printf("%s\n",bo -> book_name);
                            ty = find_wgc(type_head, &bo -> book_type, type_name_cmp); //查找图书馆对应的图书类型
                            if(NULL == ty)
                            {
                                printf("图书馆无该类型的书\n");
                            }
                            else
                            {
                                printf("确认归还------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    establish_node(ty -> head, bo, _MODE_AFTER); //图书馆对应类型书籍加1

                                    ty -> type_book++; //图书馆对应类型书籍总数加1
                                    surplus_book_num++; //图书馆剩余图书加1
                                    dale_wgc(us -> head, bo -> book_name, book_name_cmp); //该用户借阅的图书信息减1
                                    us -> user_book_num--; //该用户借阅的图书总数减1
                                    us -> user_record_num++;
                                    time(&tt);
                                    t = localtime(&tt);
                                    sprintf(recort_time,"%4d年%02d月%02d日->%02d:%02d:%02d->%s---->归还书籍：%s\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, us -> user_name, bo -> book_name);
                                    establish_node(us -> head2, recort_time, _MODE_AFTER); //该用户归还书籍记录加1
                                    printf("%s\n", recort_time);
                                    save_user(user_head);
                                    system("clear");
                                }
                                else
                                {
                                    system("clear");
                                    while(a != '\n')
                                    {
                                        a = getchar();
                                    }
                                    continue;
                                }
                            }
                        }
                        while(a != '\n')
                        {
                            a = getchar();
                        }
                    }
                    else if(3 == n)
                    {
                        if((us -> user_record_num) < 1)
                        {
                            printf("目前暂任何借阅记录");
                            printf("返回上一级------>请按1回车\n\n退出系统------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        a = 'c';
                        ergodic(us -> head2, record_show); //查看个人借阅记录
                        printf("查看成功\n");
                        printf("返回上一级------->按任意建回车\n");
                        scanf("%s", name);
                        while(a != '\n')
                        {
                            a = getchar();
                        }
                        system("clear");
                    }
                    else if(4 == n)
                    {
                        a = 'c';
                        user_show(us); //查看个人信息
                        printf("查看成功\n");
                        printf("返回上一级------->按任意建回车\n");
                        scanf("%s", name);
                        while(a != '\n')
                        {
                            a = getchar();
                        }
                        system("clear");
                    }
                    else if(5 == n)
                    {
                        a = 'c';
                        printf("请输入新的用户名：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(us -> user_name, name);
                        printf("请输入新的用户密码：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 8)
                            {
                                printf("输入用户密码格式错误 (用户名最长为8个字符)\n");
                                printf("请重新输入新的用户密码：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(us -> user_passwd, name);
                        printf("请输入新的用户id：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 10)
                            {
                                printf("输入用户id格式错误 (用户名最长为10个字符)\n");
                                printf("请重新输入新的用户密码：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(us -> user_id, name);
                        printf("请输入新的用户手机号码：");
                        scanf("%ld", &us -> user_ipone);
                        printf("请输入新的用户性别：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 3)
                            {
                                printf("输入用户性别格式错误 (用户性别最长为3个字符)\n");
                                printf("请重新输入新的用户性别：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(us -> user_sex, name);
                        printf("请输入新的用户住址：");
                        while(1)
                        scanf("%s", name);
                        {
                            if(strlen(name) > 30)
                            {
                                printf("输入用户住址格式错误 (用户住址最长为30个字符)\n");
                                printf("请重新输入新的住址性别：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(us -> user_address, name);
                        printf("修改成功\n");
                        save_user(user_head);
                        printf("返回上一级------->按任意建回车\n");
                        scanf("%s", name);
                        while(a != '\n')
                        {
                            a = getchar();
                        }
                    }
                    else if(6 == n)
                    {
                        break;
                        system("clear");
                    }
                }

            }
        }
        else if(strcmp(N, "2") == 0)
        {
            if(initial_number < 1)
            {
                initial_number++;
                printf("管理员初始用户名：%s\n",wgc_name);
                printf("管理员初始密码：%s\n",wgc_passwd);
                printf("首次登陆，建议更改初始用户名及密码\n更改请按1回车,无需更改请按其他健回车\n");
                printf("请输入你的选项：");
                scanf("%s", name);
                if(strcmp(name, "1") == 0)
                {
                    printf("请输入新的用户名：");
                    scanf("%s", name);
                    while(1)
                    {
                        if(strlen(name) > 20)
                        {
                            printf("输入用户名格式错误 (用户名最长为20个字符)");
                            printf("请重新输入新的用户名：");
                            scanf("%s", name);
                        }
                        else
                        {
                            break;
                        }
                    }
                    strcpy(wgc_name, name);
                    printf("请输入新的用户名密码：");
                    scanf("%s", name2);
                    while(1)
                    {
                        if(strlen(name2) > 8)
                        {
                            printf("输入用户密码格式错误 (用户名最长为8个字符)");
                            printf("请重新输入新的用户密码：");
                            scanf("%s", name2);
                        }
                        else
                        {
                            break;
                        }
                    }
                    strcpy(wgc_passwd, name2);
                }
            }
            printf("请输入管理员用户名：");
            scanf("%s", name);
            while(1)
            {
                if(strlen(name) > 20)
                {
                    printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                    printf("请重新输入用户名：");
                    scanf("%s", name);
                }
                else
                {
                    break;
                }
            }
            printf("请输入管理员用户密码：");
            scanf("%s", name2);
            while(1)
            {
                if(strlen(name2) > 8)
                {
                    printf("输入用户密码格式错误 (用户名最长为8个字符)\n");
                    printf("请重新输入用户密码：");
                    scanf("%s", name2);
                }
                else
                {
                    break;
                }
            }
            if((strcmp(name, wgc_name) + (strcmp(name2, wgc_passwd)) != 0))
            {
                printf("用户或用户名错误\n");
                printf("如果忘记，建议去死\n");
                continue;
            }
            else
            {
                system("clear");
                printf("-------------------欢迎进入管理员界面--------------------\n");
                while(1)
                {
                    printf("---------------您可以进行以下操作---------------\n");
                    printf("1、添加图书信息\n");
                    printf("2、修改图书信息\n");
                    printf("3、删除图书信息\n");
                    printf("4、查找图书信息\n");
                    printf("5、查看所有图书信息\n");
                    printf("6、添加图书类型信息\n");
                    printf("7、修改图书类型信息\n");
                    printf("8、删除图书类型信息\n");
                    printf("9、查找图书类型信息\n");
                    printf("10、查看所有图书类型\n");
                    printf("11、查阅归还记录\n");
                    printf("12、添加用户信息\n");
                    printf("13、修改用户信息\n");
                    printf("14、删除用户信息\n");
                    printf("15、查找用户信息\n");
                    printf("16、查看所有用户信息\n");
                    printf("17、修改个人信息\n");
                    printf("18、保存\n");
                    printf("19、退出\n");
                    printf("请输入你的选项：");
                    scanf("%d", &n);
                    system("clear");
                    if(1 == n)
                    {
                        a = 'c';
                        printf("1、新增图书类型再添加\n");
                        printf("2、添加到现已有的图书类型\n");
                        printf("请输入你的选项：");
                        scanf("%s", name2);
                        if(strcmp(name2, "1") == 0)
                        {
                            printf("请输入图书类型id：");
                            scanf("%d", &type.type_id);
                            while(a != '\n')
                            {
                                a = getchar();
                            }
                            printf("请输入图书类型name：");
                            scanf("%s", type.type_name);
                            type.type_book = 0; //该类型图书总数置0
                            printf("确认新增------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                type.head = establish_head(sizeof(struct book_ation)); //创建该类型图书的头
                                establish_node(type_head, &type, _MODE_AFTER); //新增图书类型
                                printf("新增图书类型成功--------------\n");
                                type_num++;
                                save(user_head, type_head);
                                system("clear");
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                continue;
                            }
                            ty = find_wgc(type_head, type.type_name, type_name_cmp);
                            printf("输入新增的图书信息\n");
                            printf("请输入图书id：");
                            scanf("%d", &book.book_id);
                            while(a != '\n')
                            {
                                a = getchar();
                            }
                            strcpy(book.book_type, type.type_name);
                            printf("请输入图书name：");
                            scanf("%s", book.book_name);
                            printf("请输入图书author：");
                            scanf("%s", book.book_author);
                            printf("确认新增------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                establish_node(ty -> head, &book, _MODE_AFTER); //新增到该类型图书信息
                                book_num++; //图书总数加1
                                ty -> type_book++; //该类型图书加1
                                surplus_book_num++; //图书馆剩余图书总数加1
                                system("clear");
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                continue;
                            }
                            
                        }
                        else if(strcmp(name2, "2") == 0)
                        {
                            if(type_num < 1)
                            {
                                printf("暂时无任何图书类型，请先新增图书类型再新增图书信息\n");
                                continue;
                            }
                            ergodic(type_head, type_show3); //便利所有图书类型
                            printf("***                     ***\n");
                            printf("请输入要增添到的图书类型name：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 10)
                                {
                                    printf("输入格式错误 (最长为10个字符)\n");
                                    printf("请重新输入：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            ty = find_wgc(type_head, name, type_name_cmp); //书籍类型校验
                            if(NULL == ty)
                            {
                                printf("输入的name有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;  
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                            else
                            {
                                
                                printf("请输入图书id：");
                                scanf("%d", &book.book_id);
                                printf("请输入图书name：");
                                while(1)
                                {
                                    if(strlen(name) > 20)
                                    {
                                        printf("输入格式错误 (名字最长为20个字符)\n");
                                        printf("请重新输入新的名字：");
                                        scanf("%s", name);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                strcpy(book.book_name, name);
                                printf("请输入图书author：");
                                while(1)
                                {
                                    if(strlen(name) > 20)
                                    {
                                        printf("输入格式错误 (名字最长为20个字符)\n");
                                        printf("请重新输入新的名字：");
                                        scanf("%s", name);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                strcpy(book.book_author, name);
                                printf("确认新增------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                     establish_node(ty -> head, &book, _MODE_AFTER); //添加图书信息
                                    (ty -> type_book)++;
                                    book_num++;
                                    surplus_book_num++;
                                    save(user_head, type_head);
                                    system("clear");
                                }
                                else
                                {
                                    system("clear");
                                    while(a != '\n')
                                    {
                                        a = getchar();
                                    }
                                    continue;
                                }
                               
                            }
                        }
                        else
                        {
                            printf("输入选项有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                    }
                    else if(2 == n)
                    {
                        a = 'c';
                        if(book_num < 1)
                        {
                            printf("暂时无任何图书，请重新选择\n");
                            continue;
                        }
                        ergodic(type_head, type_show3); //便利所有图书类型
                        printf("***                     ***\n");
                        printf("请输入要增添到的图书类型名称：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ty = find_wgc(type_head, name2, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            if((ty -> type_book) < 1)
                            {
                                printf("该类型暂无图书,请重新选择\n");
                                continue;
                            }
                            else
                            {
                                ergodic(ty -> head, book_show); //便利该类型所有图书信息
                                printf("***                     ***\n");
                                printf("请输入图书name：");
                                scanf("%s", name);
                                while(1)
                                {
                                    if(strlen(name) > 10)
                                    {
                                        printf("输入格式错误 (最长为10个字符)\n");
                                        printf("请重新输入：");
                                        scanf("%s", name);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                bo = find_wgc(ty -> head, name, book_name_cmp); //图书信息校验
                                if(NULL == bo)
                                {
                                    printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                    scanf("%s", name);
                                    if(strcmp(name, "1") == 0)
                                    {
                                        system("clear");
                                        continue;  
                                    }
                                    else
                                    {
                                        system("clear");
                                        break;
                                    }
                                }
                                else
                                {
                                    printf("请输入新的图书id：");
                                    scanf("%d", &bo -> book_id);
                                    while(a != '\n')
                                    {
                                        a = getchar();
                                    }
                                    //strcpy(book.book_type, type.type_name);
                                    printf("请输入新的图书name：");
                                    scanf("%s", bo -> book_name);
                                    printf("请输入新的图书author：");
                                    scanf("%s", bo -> book_author);
                                    save(user_head, type_head);
                                    printf("修改操作成功\n");
                                    printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                                    scanf("%s", name);
                                    if(strcmp(name, "1") == 0)
                                    {
                                        system("clear");
                                        continue;  
                                    }
                                    else
                                    {
                                        system("clear");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else if(3 == n)
                    {
                        a = 'c';
                        if(book_num < 1)
                        {
                            printf("暂无任何图书信息");
                            break;
                        }
                        ergodic(type_head, type_show); //便利所有图书类型
                        printf("***                     ***\n");
                        printf("请输入要增添到的图书类型名称：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ty = find_wgc(type_head, name2, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%d", &idd);
                            if(1 == idd)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            if((ty -> type_book) < 1)
                            {
                                printf("该类型暂无图书\n");
                                printf("返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;  
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                            ergodic(ty -> head, book_show);//显示该类型所有图书信息
                            printf("***                     ***\n");
                            printf("请输入图书name：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 10)
                                {
                                    printf("输入格式错误 (最长为10个字符)\n");
                                    printf("请重新输入：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            bo = find_wgc(ty -> head, name, book_name_cmp); //图书信息校验
                            if(NULL == bo)
                            {
                                printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;  
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                            else
                            {
                                printf("确认删除------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    dale_wgc(ty -> head, &id, book_cmp); //删除图书信息
                                    ty -> type_book--; //该类型图书减1
                                    book_num--; //图书总数减1
                                    surplus_book_num--; //图书馆剩余图书减1
                                    save(user_head, type_head);
                                    system("clear");
                                }
                                else
                                {
                                    system("clear");
                                    while(a != '\n')
                                    {
                                        a = getchar();
                                    }
                                    continue;
                                }
                            }
                        }

                    }
                    else if(4 == n)
                    {
                        if(book_num < 1)
                        {
                            printf("暂无任何图书信息");
                            break;
                        }
                        ergodic(type_head, type_show3); //便利所有图书类型
                        printf("***                     ***\n");
                        printf("请输入要增添到的图书类型名称：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ty = find_wgc(type_head, name2, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入的名称有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            if((ty -> type_book) < 1)
                            {
                                printf("该类型暂无图书\n");
                                break;
                            }
                            ergodic(ty -> head, book_show2);//显示该类型所有图书信息
                            printf("***                     ***\n");

                            printf("请输入图书name：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 10)
                                {
                                    printf("输入格式错误 (最长为10个字符)\n");
                                    printf("请重新输入：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            bo = find_wgc(ty -> head, name, book_name_cmp); //图书信息校验
                            if(NULL == bo)
                            {
                                printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;  
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                            else
                            {
                                book_show(bo);
                                printf("查找成功\n");
                                printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                                scanf("%s", name);
                                if(strcmp(name, "1") == 0)
                                {
                                    system("clear");
                                    continue;  
                                }
                                else
                                {
                                    system("clear");
                                    break;
                                }
                            }
                        }
                    }
                    else if(5 == n)
                    {
                        if(surplus_book_num < 1)
                        {
                            printf("图书馆库存暂无任何图书，请先新增图书\n");
                            continue;
                        }
                        struct Node_wgc* ucr;
                        for(ucr= type_head -> tou.next; ucr != &(type_head -> tou); ucr = ucr -> next)
                        {
                            
                            p = type_show2(ucr -> data);
                            printf("该类型有以下：\n");
                            ergodic(p, book_show);//显示该类型所有图书信息
                            printf("\n");
                        }
                        printf("显示成功\n");
                        printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            system("clear");
                            continue;  
                        }
                        else
                        {
                            system("clear");
                            break;
                        }
                    }
                    else if(6 == n)
                    {
                        printf("请输入图书类型id：");
                        scanf("%d", &type.type_id);
                        printf("请输入图书类型name：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 20)
                            {
                                printf("输入图书类型格式错误 (最长为20个字符)\n");
                                printf("请重新输入新的图书类型名称：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(type.type_name, name);
                        type.type_book = 0; //该类型图书总数置0
                        printf("确认新增------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            type.head = establish_head(sizeof(struct book_ation)); //创建该类型图书的头
                            establish_node(type_head, &type, _MODE_AFTER);
                            printf("新增图书类型成功--------------\n");
                            type_num++; //图书类型总数加1
                            save(user_head, type_head);
                            system("clear");
                        }
                        else
                        {
                            system("clear");
                            while(a != '\n')
                            {
                                a = getchar();
                            }
                            continue;
                        }
                        
                    }
                    else if(7 == n)
                    {
                        if(type_num < 1)
                        {
                            printf("暂无任何图书类型，请重新选择\n");
                            continue;
                        }
                        ergodic(type_head, type_show); //便利所有图书类型
                        printf("***                     ***\n");
                       printf("请输入要增添到的图书类型名称：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ty = find_wgc(type_head, name2, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            printf("请输入新的图书类型id：");
                            scanf("%d", &ty -> type_id);
                            printf("请输入新的图书类型名称：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 20)
                                {
                                    printf("输入图书类型格式错误 (用户名最长为20个字符)\n");
                                    printf("请重新输入新的图书类型名称：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            strcpy(ty -> type_name, name);
                            ergodic_(ty -> head, xiugai, name);
                            save(user_head, type_head);
                            printf("修改成功\n");
                            printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }

                    }
                    else if(8 == n)
                    {
                        ergodic(type_head, type_show3); //便利所有图书类型
                        printf("***                     ***\n");
                        printf("请输入要增添到的图书类型名称：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ty = find_wgc(type_head, name2, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            printf("确认新增------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                dale_wgc(type_head, &id, type_cmp);
                                type_num--;
                                save(user_head, type_head);
                                system("clear");
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                continue;
                            }
                            
                        }
                    }
                    else if(9 == n)
                    {
                        if(type_num < 1)
                        {
                            printf("图书馆暂无任何图书类型\n");
                            continue;
                        }
                        printf("请输入要增添到的图书类型名称：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ty = find_wgc(type_head, name2, type_name_cmp); //书籍类型校验
                        if(NULL == ty)
                        {
                            printf("输入的id有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                        else
                        {
                            type_show(ty);
                            printf("显示成功\n");
                            printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                    }
                    else if(10 == n)
                    {
                        if(type_num < 1)
                        {
                            printf("暂无任何图书类型\n");
                            continue;
                        }
                        ergodic(type_head, type_show); //便利所有图书类型
                        printf("显示成功\n");
                        printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            system("clear");
                            continue;  
                        }
                        else
                        {
                            system("clear");
                            break;
                        }
                    }
                    else if(11 == n)
                    {
                        if(user_num < 1)
                        {
                            printf("以存在用户暂无任何借阅信息\n");
                            continue;
                        }
                        ergodic(user_head, user_show);
                        printf("请输入你要查询的用户名：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 10)
                            {
                                printf("输入用户名格式错误 (用户名最长为10个字符)\n");
                                printf("请重新输入：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        us = find_wgc(user_head, name, user_name_cmp);
                        if(us == NULL)
                        {
                            printf("用户名输入错误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                break;
                            }
                        }
                        else
                        {
                            ergodic(us -> head2, record_show);
                            printf("显示成功\n");
                            printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                    }
                    else if(12 == n)
                    {
                        printf("请输入用户名：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(use.user_name, name);
                        printf("请输入用户密码：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 8)
                            {
                                printf("输入用户密码格式错误 (用户名最长为8个字符)\n");
                                printf("请重新输入新的用户密码：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(use.user_passwd, name);
                        printf("请输入用户id：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 10)
                            {
                                printf("输入用户id格式错误 (用户名最长为10个字符)\n");
                                printf("请重新输入新的用户密码：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(use.user_id, name);
                        printf("请输入用户手机号码：");
                        scanf("%ld", &use.user_ipone);
                        printf("请输入用户性别：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 3)
                            {
                                printf("输入用户性别格式错误 (用户性别最长为3个字符)\n");
                                printf("请重新输入新的用户性别：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(use.user_sex, name);
                        printf("请输入用户住址：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 30)
                            {
                                printf("输入用户住址格式错误 (用户住址最长为30个字符)\n");
                                printf("请重新输入新的住址性别：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(use.user_address, name);
                        use.user_book_num = 0;
                        use.user_record_num = 0;
                        printf("确认新增------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            use.head = establish_head(sizeof(struct book_ation));
                            use.head2 = establish_head(sizeof(struct user_record));
                            establish_node(user_head, &use, _MODE_AFTER);
                            user_num++;
                            save(user_head, type_head);
                            system("clear");
                        }
                        else
                        {
                            system("clear");
                            while(a != '\n')
                            {
                                a = getchar();
                            }
                            continue;
                        }
                    }
                    else if(13 == n)
                    {
                        if(user_num < 1)
                        {
                            printf("暂无任何用户信息\n");
                            continue;
                        }
                        ergodic(user_head, user_show);
                        printf("请输入你要修改的用户名：");
                        scanf("%s", name);
                        us = find_wgc(user_head, name, user_name_cmp);
                        if(us == NULL)
                        {
                            printf("用户名输入错误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                break;
                            }
                        }
                        else
                        {
                            printf("请输入新的用户名：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 20)
                                {
                                    printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                    printf("请重新输入新的用户名：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            strcpy(us -> user_name, name);
                            printf("请输入新的用户密码：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 8)
                                {
                                    printf("输入用户密码格式错误 (用户名最长为8个字符)\n");
                                    printf("请重新输入新的用户密码：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            strcpy(us -> user_passwd, name);
                            printf("请输入新的用户id：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 10)
                                {
                                    printf("输入用户id格式错误 (用户名最长为10个字符)\n");
                                    printf("请重新输入新的用户密码：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            strcpy(us -> user_id, name);
                            printf("请输入新的用户手机号码：");
                            scanf("%ld", &us -> user_ipone);
                            printf("请输入新的用户性别：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 3)
                                {
                                    printf("输入用户性别格式错误 (用户性别最长为3个字符)\n");
                                    printf("请重新输入新的用户性别：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            strcpy(us -> user_sex, name);
                            printf("请输入新的用户住址：");
                            scanf("%s", name);
                            while(1)
                            {
                                if(strlen(name) > 30)
                                {
                                    printf("输入用户住址格式错误 (用户住址最长为30个字符)\n");
                                    printf("请重新输入新的住址性别：");
                                    scanf("%s", name);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            strcpy(us -> user_address, name);
                            save(user_head, type_head);
                            printf("修改成功\n");
                            printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                    }
                    else if(14 == n)
                    {
                        if(user_num < 1)
                        {
                            printf("暂无任何用户信息\n");
                            continue;
                        }
                        ergodic(user_head, user_show);
                        printf("请输入你要删除用户的用户名：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        us = find_wgc(user_head, name, user_name_cmp);
                        if(us == NULL)
                        {
                            printf("用户名输入错误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                break;
                            }
                        }
                        else
                        {
                            printf("确认删除------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                dale_wgc(user_head, us -> user_name, user_name_cmp);
                                user_num--;
                                save(user_head, type_head);
                                system("clear");
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                continue;
                            }
                        }
                    }
                    else if(15 == n)
                    {
                        if(user_num < 1)
                        {
                            printf("暂无任何用户信息\n");
                            continue;
                        }
                        ergodic(user_head, user_show);
                        printf("请输入你要查找用户的用户名：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 20)
                            {
                                printf("输入用户名格式错误 (用户名最长为20个字符)\n");
                                printf("请重新输入新的用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        us = find_wgc(user_head, name, user_name_cmp);
                        if(us == NULL)
                        {
                            printf("用户名输入错误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;
                            }
                            else
                            {
                                system("clear");
                                while(a != '\n')
                                {
                                    a = getchar();
                                }
                                break;
                            }
                        }
                        else
                        {
                            user_show(us);
                            printf("显示成功\n");
                            printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                            scanf("%s", name);
                            if(strcmp(name, "1") == 0)
                            {
                                system("clear");
                                continue;  
                            }
                            else
                            {
                                system("clear");
                                break;
                            }
                        }
                    }
                    else if(16 == n)
                    {
                        if(user_num < 1)
                        {
                            printf("暂无任何用户信息\n");
                            continue;
                        }
                        ergodic(user_head, user_show); //查看所有用户信息
                        printf("显示成功\n");
                        printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            system("clear");
                            continue;  
                        }
                        else
                        {
                            system("clear");
                            break;
                        }
                    }
                    else if(17 == n)
                    { 
                        printf("请输入新的管理员用户名：");
                        scanf("%s", name);
                        while(1)
                        {
                            if(strlen(name) > 20)
                            {
                                printf("输入管理员用户名格式错误 (管理员用户名最长为20个字符)\n");
                                printf("请重新输入新的管理员用户名：");
                                scanf("%s", name);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(wgc_name, name);
                        printf("请输入新的管理员密码：");
                        scanf("%s", name2);
                        while(1)
                        {
                            if(strlen(name2) > 8)
                            {
                                printf("输入管理员密码格式错误 (管理员密码最长为8个字符)\n");
                                printf("请重新输入新的管理员密码：");
                                scanf("%s", name2);
                            }
                            else
                            {
                                break;
                            }
                        }
                        strcpy(wgc_passwd, name2);
                        save(user_head, type_head);
                        printf("修改成功\n");
                        printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            system("clear");
                            continue;  
                        }
                        else
                        {
                            system("clear");
                            break;
                        }
                    }
                    else if(18 == n)
                    {
                        printf("确认保存------>请按1回车\n返回上一级------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            save(user_head, type_head);
                            system("clear");
                            continue;
                        }
                        else
                        {
                            system("clear");
                            while(a != '\n')
                            {
                                a = getchar();
                            }
                            continue;
                        }
                    }
                    else if(19 == n)
                    {
                        break;
                    }
                    else
                    {
                        printf("输入选项有误\n返回上一级------>请按1回车\n\n退出登陆------->按任意建回车\n请输入你的选项：");
                        scanf("%s", name);
                        if(strcmp(name, "1") == 0)
                        {
                            system("clear");
                            continue;  
                        }
                        else
                        {
                            system("clear");
                            break;
                        }
                    }

                }
            }
        }
        else if(strcmp(N, "3") == 0)
        {
            if(surplus_book_num < 1)
            {
                printf("图书馆库存暂无任何图书，请先新增图书\n");
                continue;
            }
            struct Node_wgc* ucr;
            for(ucr= type_head -> tou.next; ucr != &(type_head -> tou); ucr = ucr -> next)
            {
                
                p = type_show2(ucr -> data);
                printf("该类型有以下：\n");
                ergodic(p, book_show);//显示该类型所有图书信息
                printf("\n");
            }
            printf("显示成功\n");
            printf("返回上一级------->请按1回车\n退出登陆------->按任意建回车\n请输入你的选项：");
            scanf("%s", name);
            if(strcmp(name, "1") == 0)
            {
                system("clear");
                continue;  
            }
            else
            {
                system("clear");
                break;
            }
        }
        else if(strcmp(N, "4") == 0)
        {
            system("clear");
            break;
        }
        else
        {
            printf("输入选项有误\n返回上一级------>请按1回车\n\n退出系统------->按任意建回车\n请输入你的选项：");
            scanf("%s", name);
            if(strcmp(name, "1") == 0)
            {
                system("clear");
                continue;  
            }
            else
            {
                system("clear");
                break;
            }
        }

    }
    return 0;
}
